require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../css/commCss/basic.css')
require('animate.css')
const axios = require('axios')

var CaptchaMini = require("captcha-mini")
require('../css/enroll.less')


document.addEventListener('DOMContentLoaded', function () {
    const iphone = document.querySelector('#iphone')
    const captcha = document.querySelector('#captcha')
    const pwd = document.querySelector('#pwd')
    const checkpwd = document.querySelector('#checkpwd')
    const btn = document.querySelector('#btn')
    const errMsg = document.querySelector('#errMsg')
    let node = ''
    let captcha1 = new CaptchaMini({
        lineWidth: 1, //线条宽度
        lineNum: 6, //线条数量
        dotR: 2, //点的半径
        dotNum: 25, //点的数量
        preGroundColor: [10, 80], //前景色区间
        backGroundColor: [150, 250], //背景色区间
        fontSize: 100, //字体大小
        fontFamily: ['Georgia', '微软雅黑', 'Helvetica', 'Arial'], //字体类型
        fontStyle: 'stroke', //字体绘制方法，有fill和stroke
        content: 'abcdefghijklmnopqrstuvwcanvas', //验证码内容
        length: 4 //验证码长度
    });
    captcha1.draw(document.querySelector('#captcha1'), function (r) {
        node = r
        console.log(node);
    });




    btn.addEventListener('click', function () {
        if (!/^1[3-9][0-9]{9}$/.test(iphone.value)) {
            errMsg.textContent = '手机号码错误'
            return;
        } else if ( captcha.value!= node) {
            errMsg.textContent = '验证码错误'
            return;
        } else if (!/^[a-zA-Z]\w{5,11}$/.test(pwd.value)) {
            errMsg.textContent = '密码错误'
        } else if (pwd.value != checkpwd.value) {
            errMsg.textContent = '两次密码不一致'
        } else {
            errMsg.textContent = ''
            axios.post('http://139.9.177.51:8099/users/add', {
                account: iphone.value,
                password: pwd.value
            }).then(function (res) {
                iphone.value = pwd.value = checkpwd.value = ''
                if (res.data.status == 0) {
                    location.href = "./landing.html"
                    console.log(1);
                }
            })
        }

    })

})